package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @PostMapping
    @ApiOperation("新增套餐")
    public Result insertSetMeal(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐:{}",setmealDTO);
        setmealService.insertSetMeal(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("套餐的分页查询")
    public Result<PageResult> selectAll(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询:{}",setmealPageQueryDTO);
      PageResult result=setmealService.selectAll(setmealPageQueryDTO);
      return Result.success(result);
    }
    @DeleteMapping
    @ApiOperation("套餐的删除")
    public Result deleteSetMeal(@RequestParam List<Long> ids){
        setmealService.deleteSetMeal(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> selectById(@PathVariable Long id){
        log.info("查询套餐id:{}",id);
        SetmealVO setmealVO= setmealService.selectById11(id);
        return Result.success(setmealVO);
    }
    @PutMapping
    @ApiOperation("套餐的修改")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("套餐修改:{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }
    @PostMapping("status/{status}")
    @ApiOperation("套餐起售,停售")
    public Result staterStop(@PathVariable Integer status,Long id){
        log.info("套餐起售,停售:{}",status,id);
        setmealService.staterStop(status,id);
        return Result.success();
    }


}
